<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $options->storename; ?></title>
<link rel='stylesheet' href='<?php echo base_url(); ?>style/adminstyle.css' />
<link rel='stylesheet' href='<?php echo base_url(); ?>style/flora.datepicker.css' />
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>js/ui.datepicker.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>js/ajaxfileupload.js"></script>


<script type="text/javascript" src="<?php echo base_url(); ?>js/ajax.js"></script>

<script type="text/javascript">

//select all/select none

$(document).ready(function() {
        
        //select all/select none visible
        $("#selecting").show();
        
        
        
        $("#selall a").click(function()
        { 
                $("input[@type=checkbox]").each(function()
                {
                        this.checked = 'yes'; //checked_status;
                });
                return false;
        });
        
        $("#selnone a").click(function()
        {  
                $("input[@type=checkbox]").each(function()
                {
                        this.checked = ''; //checked_status;
                });
                return false;
        });
        
        //datepicker for event creation
        
        $("#startdate").datepicker({ 
                minDate: 0,
                dateFormat: "yy-mm-dd",
                maxDate: 365, 
                showOn: "both", 
                buttonImage: "<?php echo base_url(); ?>images/calendar.gif", 
                buttonImageOnly: true 
        });
        
        $("#enddate").datepicker({ 
                minDate: 0,
                dateFormat: "yy-mm-dd",
                maxDate: 365, 
                showOn: "both", 
                buttonImage: "<?php echo base_url(); ?>images/calendar.gif", 
                buttonImageOnly: true 
        });
        
        //uploading an image
        
        $("#uploadimage").click(function() {
                if ($("#imgfile").val() != "") {
                        $.ajaxFileUpload({
                                secureuri:false,
                                fileElementId:'imgfile',
                                dataType: 'POST',
                                url: "<?php echo site_url(); ?>/admin/product/ajax_upload/",
                                success: function(msg){
                                        if (msg.substring(0, 4) != 'http') {
                                                alert(msg);
                                        } else {
                                                $("#media").append('<img class="picture" src="' + msg + '" />');
                                                $("#media").append('<input type="hidden" name="images[]" value="' + msg + '" />');
                                        }
                                        $("#imgfile").val('');
                                        
                                }
                        });
                        return false;
                } else {
                        alert("Please choose a file to upload first by clicking on the Browse button.");
                }
        });
        
        //category adding
        
        $(".addcatform").hide();
        $(".addcatform").append("<input name='catname' />");
        
        /*
         *   START DEBUG
         */
                //alert("page refreshed");
        /*
         *   END DEBUG
         */       
        
                $("#addcat_top").click(function() {
                        $(".addcatform").hide();
                        $("#addcatform_top").fadeIn('slow');
                        $("#addcatform_top input").focus();
                        return false;
                });
        
                $("#addcatform_top input").keydown(function(e) {

                        if (e.keyCode == 13) { //ENTER pressed
                                //submit the new category
                                $.ajax({
                                        type: "POST",
                                        url: "<?php echo site_url(); ?>/admin/category/ajax_addcategory/",
                                        data: "catid=-1&catname="+$("#addcatform_top input").val(),
                                        success: function(msg){
                                                
                                                $("#addcatform_top").hide();
                                                $("#addcatform_top input").val("");
                                                if (msg != '') {
                                                        $("#addcatshere_top").append("&nbsp;&nbsp;&nbsp;");
                                                        $("#addcatshere_top").append(msg);
                                                }
                                                
                                        }
                                });
                                return false;
                        }
                        if (e.keyCode == 27) { //ESCAPE pressed
                                //cancel
                                $("#addcatform_top").fadeOut('slow');
                                $("#addcatform_top input").val("");
                        }
                        
                        
                
                });
                 
        
        
        <?php foreach ($categories as $category) { ?>
                $("#addcat_<?=$category->catid?>").click(function() {
                        $(".addcatform").hide();
                        $("#addcatform_<?=$category->catid?>").fadeIn('slow');
                        $("#addcatform_<?=$category->catid?> input").focus();
                        return false;
                });
        
                $("#addcatform_<?=$category->catid?> input").keydown(function(e) {

                        if (e.keyCode == 13) { //ENTER pressed
                                //submit the new category
                                $.ajax({
                                        type: "POST",
                                        url: "<?php echo site_url(); ?>/admin/category/ajax_addcategory/",
                                        data: "catid=<?=$category->catid?>&catname="+$("#addcatform_<?=$category->catid?> input").val(),
                                        success: function(msg){
                                                $("#addcatform_<?=$category->catid?>").hide();
                                                $("#addcatform_<?=$category->catid?> input").val("");
                                                $("#addcatshere_<?=$category->catid?>").append("<?=$category->tabs?>&nbsp;&nbsp;&nbsp;");
                                                $("#addcatshere_<?=$category->catid?>").append(msg);
                                                
                                        }
                                });
                                return false;
                        }
                        if (e.keyCode == 27) { //ESCAPE pressed
                                //cancel
                                $("#addcatform_<?=$category->catid?>").fadeOut('slow');
                                $("#addcatform_<?=$category->catid?> input").val("");
                        }
                        
                        
                
                });
                 
        <?php } ?>
        
        
        
     
});
</script>

</head>
<body><?php if (empty($location)) $location = ''; ?>
	<div id="header">
		<span class="busbylogo"><img src="<?php echo base_url(); ?>images/busbyhead.jpg" /></span>
		
		
		<span class="hello">
			<b><?php echo $options->storename; ?> ( <?php echo anchor("","Storefront &raquo;"); ?> )</b> | <?php echo anchor("admin/settings","Settings"); ?> | <?php echo anchor("admin/help","Help"); ?> | <?php echo anchor("admin/login/logout","Logout"); ?>		
		</span>
	<span class="gsearch">
			<form method="get" action="http://images.google.ca/images" target="_blank" name="searchform" id="googlesearchform">
				<input type="text" name="q" id="s" value="" size="25" />
				<input name=btnG type=submit value="Google Image Search">
			<!-- ul>
			<li><a href="advanced_search.php">Show search options</a></li>
			<li><a href="">Create a category</a></li>
			</ul -->
			</form>
		</span>
	</div>
	
<div id="sidebar">
	<br />
		<ul class="upperleft">
			<li <?= ($location == 'addproduct' ? 'class="current"' : 'class="post"') ?>><a href="<?=base_url()?>index.php/admin/product/add" title="Add a Product">Add a Product</a></li>
			<li <?= ($location == 'add_page' ? 'class="current"' : 'class="post"') ?>><a href="<?=base_url()?>index.php/admin/page/add" title="Create a Page">Create a Page</a></li>
                        <li <?= ($location == 'import' ? 'class="current"' : 'class="post"') ?>><a href="<?=base_url()?>index.php/admin/import" title="Import Products">Import Products</a></li>
                        <!--li <?= ($location == 'addcategory' ? 'class="current"' : 'class="post"') ?>><a href="<?=base_url()?>index.php/admin/category/add" title="Add a Category">Add a Category</a></li-->
			<br />&nbsp;<br />
			
			<li <?= ($location == 'products' ? 'class="current"' : 'class=""') ?>><a href="<?php echo base_url(); ?>index.php/admin/products" title="Inventory ( <?=$numitems?> )">Inventory ( <?=$numitems?> )</a></li>
			<li <?= ($location == 'pages' ? 'class="current"' : 'class=""') ?>><a href="<?=base_url()?>index.php/admin/pages" title="Pages ( <?php echo $numpages; ?> )">Pages ( <?php echo $numpages; ?> )</a></li>
                        <li <?= ($location == 'categories' ? 'class="current"' : 'class=""') ?>><a href="<?=base_url()?>index.php/admin/category" title="Categories ( <?=$numcats?> )">Categories ( <?=$numcats?> )</a></li>
                        <li <?= ($location == 'events' ? 'class="current"' : 'class=""') ?>><a href="<?=base_url()?>index.php/admin/category/events" title="Manage Events ( <?=$numevents?> )">Events ( <?=$numevents?> )</a></li>
			<!--li class=""><a href="">Uploads</a></li -->
		</ul>

		
</div>
	<div id="site">
	

	
	<div id="right">
		

